本文整理汇总了C#中ObjectManager.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectManager.GetObject方法的具体用法?C# ObjectManager.GetObject怎么用?C# ObjectManager.GetObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObjectManager
的用法示例。
在下文中一共展示了ObjectManager.GetObject方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestObjectManagerGetObject
// Test object retrieval.
public void TestObjectManagerGetObject()
{
ObjectManager mgr = new ObjectManager
(null, new StreamingContext(StreamingContextStates.All));
// Register a particular object and then look for it.
Object obj = new Object();
mgr.RegisterObject(obj, 1234);
AssertSame("GetObject (1)", obj, mgr.GetObject(1234));
// Look for a non-existent object.
AssertNull("GetObject (2)", mgr.GetObject(1235));
// Record a delayed fixup for some other object.
mgr.RecordDelayedFixup(1236, "x", 1234);
// Object 1236 shouldn't exist yet.
AssertNull("GetObject (3)", mgr.GetObject(1236));
}
示例2: ObjectManagerShouldCreateObject
public void ObjectManagerShouldCreateObject()
{
var objectManager = new ObjectManager<Guid, NonSharedObject>();
var key = Guid.NewGuid();
var obj = objectManager.GetObject(key);
Assert.IsNotNull(obj);
obj = objectManager.TryGetObject(key);
Assert.IsNotNull(obj);
}
示例3: NestedValueTypes
public static bool NestedValueTypes() {
ObjectManager manager = new ObjectManager(null, new StreamingContext(StreamingContextStates.All));
Val1 val1 = new Val1(2);
manager.RegisterObject(val1, 1);
manager.RegisterObject(val1.val, 2, null, 1, Val1.valFieldInfo);
manager.RegisterObject(val1.val.Foo, 3, null, 2, Val2.fooFieldInfo);
manager.RegisterObject(val1.val.Bar, 4, null, 2, Val2.barFieldInfo);
manager.RecordFixup(4, Val3.aFieldInfo, 5);
int newValue = 42;
A a = new A(newValue);
manager.RegisterObject(a, 5);
manager.DoFixups();
Val1 valPost = (Val1)manager.GetObject(1);
return (valPost.Int32Value==newValue);
}
示例4: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
ObjectManager objmgr1 = null;
StreamingContext sc1 = new StreamingContext(StreamingContextStates.All);
ObjectIDGenerator objid1 = null;
TestFixup tstfxp1;
Int64 iRootID;
Int64 iChildID;
String strValue;
bool fFirstTime;
MemberInfo[] members = null;
try {
do
{
strLoc="Loc_174cds";
tstfxp1 = new TestFixup();
objid1 = new ObjectIDGenerator();
iRootID = objid1.GetId(tstfxp1, out fFirstTime);
strValue = "Hello Universe";
iChildID = objid1.GetId(strValue, out fFirstTime);
members = FormatterServices.GetSerializableMembers(tstfxp1.GetType());
objmgr1 = new ObjectManager(null, sc1);
iCountTestcases++;
if(objmgr1.GetObject(iRootID)!=null)
{
iCountErrors++;
Console.WriteLine("Err_753cd! Expected value not returned, " + objmgr1.GetObject(iRootID));
}
objmgr1.RecordFixup(iRootID, members[0], iChildID);
iCountTestcases++;
if(objmgr1.GetObject(iRootID)!=null)
{
iCountErrors++;
Console.WriteLine("Err_048fd! Expected value not returned, " + objmgr1.GetObject(iRootID));
}
objmgr1.RegisterObject(tstfxp1, iRootID);
iCountTestcases++;
if(objmgr1.GetObject(iRootID)==null)
{
iCountErrors++;
Console.WriteLine("Err_0943fd! Null returned");
}
iCountTestcases++;
if(!((TestFixup)(objmgr1.GetObject(iRootID))).strFixupValue.Equals("Hello World"))
{
iCountErrors++;
Console.WriteLine("Err_047fe! wrong value returned returned, " + ((TestFixup)(objmgr1.GetObject(iRootID))).strFixupValue);
}
objmgr1.RegisterObject(strValue, iChildID);
iCountTestcases++;
if(objmgr1.GetObject(iChildID)==null)
{
iCountErrors++;
Console.WriteLine("Err_90853vdf! Null returned");
}
iCountTestcases++;
if(!objmgr1.GetObject(iChildID).Equals("Hello Universe"))
{
iCountErrors++;
Console.WriteLine("Err_1084cs! wrong value returned returned, " + objmgr1.GetObject(iChildID));
}
try{
iCountTestcases++;
objmgr1.GetObject(-5);
iCountErrors++;
Console.WriteLine("Err_04872d! Exception not thrown");
}catch(ArgumentOutOfRangeException){
}catch(Exception ex){
iCountErrors++;
Console.WriteLine("Err_1083xs! Wrong Exception thrown, " + ex);
}
} while (false);
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.StackTrace);
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例5: runTest
public bool runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
ObjectManager objmgr1 = null;
ISurrogateSelector isur = null;
StreamingContext sc1 = new StreamingContext(StreamingContextStates.All);
ObjectIDGenerator objid1 = null;
TestFixup tstfxp1;
Int64 iRootID;
Int64 iChildID;
Int32 iValue;
bool fFirstTime;
MemberInfo[] members = null;
SerializationInfo serInfo1;
try {
do
{
strLoc = "Loc_8345vdfv";
tstfxp1 = new TestFixup();
iValue = 10;
objid1 = new ObjectIDGenerator();
iRootID = objid1.GetId(tstfxp1, out fFirstTime);
iChildID = objid1.GetId(iValue, out fFirstTime);
members = FormatterServices.GetSerializableMembers(tstfxp1.GetType());
objmgr1 = new ObjectManager(isur, sc1);
objmgr1.RecordDelayedFixup(iRootID, "iFixupValue", iChildID);
serInfo1 = new SerializationInfo(typeof(TestFixup), new FormatterConverter());
objmgr1.RegisterObject(tstfxp1, iRootID, serInfo1);
iCountTestcases++;
if(objmgr1.GetObject(iRootID)==null)
{
iCountErrors++;
Console.WriteLine("Err_0943fd! Null returned");
}
objmgr1.RegisterObject(iValue, iChildID);
objmgr1.DoFixups();
strLoc = "Loc_017ged";
iCountTestcases++;
if(tstfxp1.iFixupValue != iValue)
{
iCountErrors++;
Console.WriteLine("Err_753cd! Expected value not returned, " + tstfxp1.iFixupValue.ToString() + ", expected, " + iValue.ToString());
}
strLoc = "Loc_0358vdf";
try
{
iCountTestcases++;
objmgr1.RegisterObject(null, iRootID, serInfo1);
iCountErrors++;
Console.WriteLine("Err_034cd! exception not thrown");
}
catch(ArgumentNullException){}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_03472fd! Unexpected exception, " + ex.ToString());
}
try
{
iCountTestcases++;
objmgr1.RegisterObject(tstfxp1, -5, serInfo1);
iCountErrors++;
Console.WriteLine("Err_037csd! exception not thrown");
}
catch(ArgumentOutOfRangeException){}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_710ca! Unexpected exception, " + ex.ToString());
}
try
{
iCountTestcases++;
objmgr1.RegisterObject(tstfxp1, 5, null);
Console.WriteLine("Loc_048cs! exception not thrown");
}
catch(Exception ex)
{
iCountErrors++;
Console.WriteLine("Err_079cd! Unexpected exception, " + ex.ToString());
}
} while (false);
} catch (Exception exc_general ) {
++iCountErrors;
Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
}
if ( iCountErrors == 0 )
{
Console.WriteLine( "paSs. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
return true;
}
else
{
Console.WriteLine("FAiL! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
return false;
}
}
示例6: runTest
public Boolean runTest()
{
Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
int iCountErrors = 0;
int iCountTestcases = 0;
String strLoc = "Loc_000oo";
try {
do
{
ObjectManager objMan;
String str1, str2;
ISurrogateSelector isur = null;
StreamingContext sc1 = new StreamingContext(StreamingContextStates.All);
strLoc = "Loc_100aa";
objMan = new ObjectManager(isur, sc1);
iCountTestcases++;
try
{
objMan.RegisterObject(null, 0);
iCountErrors++;
printerr("Error_100bb! Expected exception not thrown");
}
catch (ArgumentNullException) {
}catch (Exception exc){
iCountErrors++;
printerr("Error_100cc! Incorrect Exception thrown: exc=="+exc.ToString());
}
strLoc = "Loc_200aa";
str1 = "Test";
objMan = new ObjectManager(isur, sc1);
objMan.RegisterObject(str1, 1);
iCountTestcases++;
if(!((String)objMan.GetObject(1)).Equals(str1))
{
iCountErrors++;
printerr("Error_200bb! Incorrect object returned");
}
strLoc = "Loc_300aa";
str1 = "Test";
objMan = new ObjectManager(isur, sc1);
iCountTestcases++;
try
{
objMan.RegisterObject(str1, -5);
iCountErrors++;
printerr("Error_300bb! Exception exception not thrown for negative Id");
}
catch (ArgumentException) {
}catch (Exception exc){
iCountErrors++;
printerr("Error_300cc! Incorrect exception thrown : exc=="+exc.ToString());
}
strLoc = "Loc_400aa";
str1 = "Test";
objMan = new ObjectManager(isur, sc1);
objMan.RegisterObject(str1, Int64.MaxValue);
iCountTestcases++;
if(!((String)objMan.GetObject(Int64.MaxValue)).Equals(str1))
{
iCountErrors++;
printerr("Error_856bdf! Incorrect object returned");
}
strLoc = "Loc_500aa";
str1 = "Test1";
str2 = "Test2";
objMan = new ObjectManager(isur, sc1);
objMan.RegisterObject(str1, 5);
try
{
objMan.RegisterObject(str2, 5);
iCountErrors++;
printerr("Error_493fh! Trying to register same ObjectID twice should throw exception");
}
catch (SerializationException)
{
}
catch (Exception exc)
{
iCountErrors++;
printerr("Loc8235vdr! Incorrect Exception thrown: \n"+exc.ToString());
}
iCountTestcases++;
if(!((String)objMan.GetObject(5)).Equals(str1))
{
iCountErrors++;
printerr("Error_500bb! Incorrect object returned");
}
Int16 i16SameValue = 20;
Int32 i32SameValue = 1310740;
objMan = new ObjectManager(isur, sc1);
objMan.RegisterObject(i16SameValue, i16SameValue.GetHashCode());
iCountTestcases++;
try
{
objMan.RegisterObject(i32SameValue, i32SameValue.GetHashCode());
}
catch(SerializationException){}
catch (Exception exc)
{
iCountErrors++;
//.........这里部分代码省略.........
示例7: ObjectManagerShouldCreateObject
public void ObjectManagerShouldCreateObject()
{
var objectManager = new ObjectManager<Guid, ICustomerRepository>();
var key = Guid.NewGuid();
var obj = objectManager.GetObject(key);
Assert.IsNotNull(obj);
obj = objectManager.TryGetObject(key);
Assert.IsNotNull(obj);
}