Actionscript specify Datatypes within Object - actionscript

var CustomerAge:int=65;
var CustomerName:String="Jane Doe";
//I want to convert the above to keep but I can't specify the datatype for each child object
var UserProfile:Object = new Object();
UserProfile.CustomerAge:int=64;
UserProfile.CustomerName:string="Jane Doe";
The below is works but I can't specify the datatype
var UserProfile:Object = new Object();
UserProfile.CustomerAge=64;
UserProfile.CustomerName="Jane Doe";
Any ideas guys?

What if you declare the elements with type when adding them to the object?
For instance:
var UserProfile:Object = new Object();
UserProfile.CustomerAge = new int(64);
UserProfile.CustomerName = new String("Jane Doe");
Hope it helps,
Rob

If you want to enforce types you should use a class not an Object. Check out this tutorial: http://www.adobe.com/devnet/flash/quickstart/creating_class_as3.html

Related

Convert datasource guid to string value in sitecore rendering

In sitecore, when getting the datasource from the renderingcontext, it returns a guid. Is there a means to convert this to the actual string value stored in the datasource field.
I want to run a "fast" query but need the path stored in the rendering context datasource instead of the guid.
Thanks,
If what you receive is a Guid, you can use
var idString = guid.ToString("B");
if what you receive is Sitecore.Data.ID, just use:
var idString = id.ToString();
The guid that you are getting is the Sitecore ID of the datasource item. You should be able to get it's path directly:
var dataSource = Sitecore.Context.Database.GetItem(RenderingContext.CurrentOrNull.Rendering.DataSource);
var dataSourcePath = dataSource.Paths.Path;

Using Generic in iOS

I am new to iOS development . I wanted to create a dictionary which is looks like
var userInformation: UserInformation = UserInformation()
var genericDictionary: Dictionary<Int,userInformation> = [Int:userInformation]()
here ,userInformation is an object of UserInformation class .
class UserInformation{
var name:String?
var phonenumber:String?
init(_ name:String ,_phoneNumber:String){
self.name = name
self.phoneNumber = phoneNumber
}
and lastly i tried genericDictionary.append(). i wanted to store name and phone number here. i don't know how it works!
i tried , but it shows various kinds of error. is it possible to do this ?
Problem is in declaration of dictionary with value type you are specifying the object that you have created instead of its type, means it should be UserInformation class type instead of instance of it userInformation. Try like this way.
var genericDictionary = [Int:UserInformation]()
Edit: With latest edit of your question I thin'k you are looking for array not dictionary, if it is true try like this way.
var array = [UserInformation]()
array.append(userInformation)
Do like this :
var genericDictionary : [Int : UserInformation] = [:]
You are declaring the dictionary using a variable instead of the class. Instead of userInformation, you need to use UserInformation like this:
var genericDictionary: Dictionary<Int,UserInformation> = [Int:UserInformation]()

Dynamic table names in Entity Framework linq

I'm using Entity Framework 6 with ASP.Net MVC 5. When using a database context object, is there a way to use a variable for the table name, without having to manually write the query?
For example:
var tableName = "NameOfTable";
result = context.tableName.Find(...);
I know that particular code won't work, because tableName is not defined in context, but is there a way to achieve the desired effect?
There are some similar questions on this site, but they never really solved the problem and they were for earlier versions of entity framework, so I'm hoping that there is an answer now.
Here's a simple solution using a switch to associate a particular Type to a table. You could also maintain use some sort of Dictionary<string, Type> object.
var tableName = "Table1";
// Get proper return type.
Type returnType;
switch(tableName) {
case "Table1":
returnType = typeof(Table1EntityType);
break;
case "Table2":
returnType = typeof(Table2EntityType);
break;
}
var query = context.Set(returnType);
// Filter against "query" variable below...
var result = query.Where(...);
-or-
var tableName = "Table1";
Dictionary<string, Type> tableTypeDict = new Dictionary<string, Type>()
{
{ "Table1", Table1Type },
{ "Table2", Table2Type }
};
var query = context.Set(tableTypeDict[tableName]);
// Filter against "query" variable below...
var result = query.Where(...);
EDIT: Modified for Entity Framework
EDIT2: Use typeof per #thepirat000 's suggestion
In addition to the helpful answers above, I also want to add this in case it helps someone else.
If you are getting this error on the "Where" clause in Mark's answer:
'DbSet does not contain a definition for 'Where' and no acceptable extension method 'Where' accepting an argument of the type 'DbSet' could be found.
Installing the Nuget Package "System.Linq.Dynamic.Core" made the error disappear for us.
If you need to access the LINQ methods and the column names from the table, you can code something like this:
var tableName = "MyTableName";
var tableClassNameSpace = "MyProject.Models.EntityModels";
using (var dbContext = new MyEntities())
{
var tableClassName = $"{tableClassNameSpace}.{tableName}";
var dynamicTableType = Type.GetType(tableClassName); // Type
var dynamicTable = dbContext.Set(dynamicTableType); // DbSet
var records = dynamicTable
.AsQueryable()
.ToDynamicList()
.OrderBy(d => d.MyColumnName)
.Select(d => new { d.MyColumnName })
.ToList();
// do stuff
}

swift access property of an object in Array, returns nil

I have been learning the swift language. I setup this vocabulary class and using this class to generate a new object "newWord". I put this object into a new Array "vocabularyListb". When I try to get the newWord.name property from the array, it returns "nil". So the question is how can I access the property of an Object that resides in an Array?
class vocabulary{
let name:String
init(name: String){
self.name = name
}
}
let vocabularyList1a = ["instigate", "constitution", "bellow", "jargon", "term"]
var vocabularyList1b = [AnyObject]()
var newWord = vocabulary(name: vocabularyList1a[0])
newWord.name
vocabularyList1b.append(newWord)
vocabularyList1b[0].name
At the moment you instantiate your vocabularyList1b as [AnyObject]. But you actually want to have an array of vocabulary objects.
So you will have to change :
var vocabularyList1b = [AnyObject]()
To:
var vocabularyList1b = [vocabulary]()
After that you can access the name variable.

how to pass two object values to single Temp Data

TempData["Amalgamation"] = SearchList;
I am using this code already in this TempData a record is there now i want to append new data which was stored in "SearchList". How can i do that?
Assuming SearchList is a List<T>
var searchList = (List<SomeType>)TempData["Amalgamation"];
searchList.Add(...);

Resources